<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () {
    return view('welcome');
});


Route::get('test/{id?}',function ($id = null){
    return route('profile');
});

Route::get('user/{ID}/test02',function (){
    return "good";
})->name('profile_param');

Route::get('user/test',function (){
    return getmypid();
})->name('profile');

Route::get('test02/{ID?}',function ($ID){
    return route('profile_param',['ID'=>$ID]);
});

Route::middleware(['throttle','bindings'])->group(function () {
    Route::prefix('admin')->group(function(){
        Route::get('/', function () {
            // Uses first & second Middleware

        });

        Route::get('test03', function () {
            // Uses first & second Middleware
            return "Hello Middleware";
        });
    });
    Route::domain('{domain}.laravel.dev')->group(function (){
        Route::get('login',function ($domain){
            return $domain;
        });
        Route::get('activity/{activity}',function (App\Activity $activity){
            return $activity->name;
        });
    });
});
/*
 * 通过中间间过滤用户ID，重定向到不同服务器
 */
Route::get('user/myAge/{age}',function ($age){
    echo "haha","<hr />";
    return "good";
})->middleware('age');
//测试控制器

Route::prefix('testC')->group(function (){
    Route::get('testC','test\Test01');

    Route::get('test02','test\Test02@index');
});
/*
 *
 * 当有定义resource路由时，photos路由将无效
Route::get('photos',function (){
    echo "bad";
});
*/
Route::resource('photos','test\Photo');

/*
 * 支持自定义资源组
 */
Route::resource('users',"test\Users",[
    'parameters' => [
        'users'  =>  'singleUser'
    ]
]);

/*
 * 测试容器自动解决控制器依赖
 */
Route::get('injection','test\Injection@index');                 //构造器中解决
Route::get('injection2/{di}','test\Injection2@index');       //方法中解决        参数按顺序传递，不按命名

//测试路由缓存
// 未测试，路由缓存不支持匿名函数，仅能使用控制器路由，否则执行 php artisan route:cache   命令失败
Route::get('kaikai',function (){
    return "Hello Route Cache!";
});
//测试析构函数 clone =
Route::get('testObj','test\TestObj');

/*
 *
 * 测试路由组
 */

Route::prefix('testV')->group(function (){

    Route::get('cgi','test\TestCgi');   //测试cgi函数

    Route::get('reflection','test\TestReflection@index');   ///测试反射类

    Route::get('preg',"test\Preg@index");                       //测试正则匹配

});




